/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package server;

import database_beans.Korisnik;
import database_beans.Role;
import database_beans.Student;
import database_beans.Zaposleni;
import exceptions.PiaDatabseColumnExistsException;
import java.sql.Date;
import java.util.Set;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.exception.ConstraintViolationException;

/**
 *
 * @author stefan
 */
public class AdminLogic {

    private static AdminLogic instance;

    private AdminLogic() {
    }

    public static synchronized AdminLogic getInstance() {
        if (instance == null) {
            instance = new AdminLogic();
        }
        return instance;
    }

    public void snimiStudenta(Student student) throws PiaDatabseColumnExistsException {
        SessionFactory sf = new Configuration().configure().buildSessionFactory();
        Session s = sf.openSession();
        try {
            Transaction transaction = s.beginTransaction();
        //Student std = new Student(student.getKorisnickoIme(), student.getLozinka(), student.getIndeks(), 
            //        student.getTipStudija(), student.getIme(), student.getPrezime(), student.getAdresa(), student.getTelefon(), true);

            // s.save(std);
            transaction.commit();
        } catch (ConstraintViolationException exp) {
            s.close();
            throw new PiaDatabseColumnExistsException("Kolona vec postoji u bazi", exp);
        } finally {
            s.close();
        }
    }

    

}
